#pragma once

#include "util/log.hpp"
#include "rtda/heap/object.h"

#include <stdexcept>

namespace jvm {
    namespace instructions {

        namespace utils {

            inline void checkNotNil(heap::ObjectPtr ref)
            {
                if (ref == nullptr) {
                    LOG_ERROR("java.lang.NullPointerException");
                    throw std::runtime_error("java.lang.NullPointerException");
                }
            }

            inline void checkIndex(size_t arrLen, int32_t index)
            {
                if (index < 0 || static_cast<size_t>(index) >= arrLen) 
                {
                    LOG_ERROR("ArrayIndexOutOfBoundsException");
                    throw std::runtime_error("ArrayIndexOutOfBoundsException");
                }
            }
        } // namespace utils


    }// namespace instructions
}// namespace jvm